package com.zust.data.web.rest;

import com.zust.data.domain.param.ChartSaveParam;
import com.zust.data.domain.param.ColumnSaveParam;
import com.zust.data.dto.ResponseDto;
import com.zust.data.dto.SessionInfo;
import com.zust.data.entity.DlChart;
import com.zust.data.serivce.ChartService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.inject.Inject;
import javax.servlet.http.HttpSession;

/**
 *
 */
@RestController
@RequestMapping("/chart")
public class ChartResource {

    @Inject
    private ChartService chartService;

    @RequestMapping("/save")
    public ResponseDto save(ChartSaveParam chartSaveParam, HttpSession session) {
        SessionInfo sessionInfo = (SessionInfo) session.getAttribute("sessionInfo");
        chartSaveParam.setUserId(sessionInfo.getId());
        return chartService.save(chartSaveParam);
    }

    @RequestMapping("/{chartId}/delete")
    public ResponseDto deleted(@PathVariable String chartId) {
        chartService.deleted(chartId);
        return new ResponseDto(true, "操作成功");
    }


    @RequestMapping("/{chartId}/doUpdate")
    public ResponseDto update(@PathVariable String chartId, HttpSession session,
                              @RequestParam("title") String title, @RequestParam("isShow") Integer isShow, @RequestParam("intro") String intro) {
        chartService.update(chartId, title, isShow, intro);
        return new ResponseDto(true, "操作成功");
    }




}
